import { asyncget_all_private_template, asyncgetweixinusers, asyncgettags, asyncbatchget } from "../../../../plugins/api.js"
import * as types from './mutation-types'
export const actionstart = function ({ commit }) {
  commit(types.SET_START)
}

export const actionfans = async function ({
  commit
}) {
  try {
    let { data, count, total } = await asyncgetweixinusers()
    const openid = data.openid;
    let arr = []
    for (let v = 0; v < openid.length; v += 99) {
      const brr = openid.slice(v, v + 99)
      const { user_info_list } = await asyncbatchget({ openid_list: brr })
      arr.push(...user_info_list)
    }
    data = arr
    commit(types.SET_FANS, { data, count, total })
  } catch (err) {
    return false
  }
}

export const actiontemplate = async function ({
  commit
}) {
  try {
    const data = await asyncget_all_private_template()
    
    commit(types.SET_TEMPLATES, data.slice(1, 100))
  } catch (err) {
    return false
  }
}

export const actiontags = async function ({
  commit
}) {
  try {
    const data = await asyncgettags()
    commit(types.SET_TAGS, data)
  } catch (err) {
    return false
  }
}
